$.extend($.fn.validatebox.defaults.rules, {
	validateTel : {
        validator : function(value, param) {
        	return (/^0?(13[0-9]|15[012356789]|18[0236789]|14[57])[0-9]{8}$/g.test(value));
        },
        message: '请输入正确的手机号码'
    }
});

EditEmployee = function(){
	return {
		
		saveEmployee : function() {
			$('#fm').form('submit', {
				url      : "/pc/employee/ediEmployee.htm",
				onSubmit : function() {
					return $("#fm").form("validate");
				},
				success  : function(data) {
					if(0 == data) {
						Ict.info("更新成功!", function() {
							Ict.closeWin();
							$("#employeeGrid").datagrid("reload");
						});
					} else if(1 == data) {
						Ict.warn("手机号码已存在,请确认!");
					} else {
						Ict.error("更新失败,稍后重试!");
					}
				}
			});
		},
		
		getCompanyId : function() {
			var departmentId = $("#deptIdHidden").val();
			$.ajax({
				url		:	"/pc/department/getCompanyId.htm",
				type	:	'POST',
				data	:	{
					'departmentId' : departmentId
				},
				dataType:	'JSON',
				async	:	false,
				success :	function(data) {
					EditEmployee.initDepartment(data, departmentId);
					EditEmployee.initHeadship(data);
				}
			});
		},
		
		initDepartment : function(companyId, departmentId) {
			$("#departmentId").combotree({
				url           : '/pc/department/deptComTree.htm?companyId=' + companyId,
				editable      : false,
				required      : true,
				panelHeight   : 200,
				onLoadSuccess : function() {
					$("#departmentId").combotree('setValue', departmentId);
				}
			});
		},
		
		initHeadship : function(companyId) {
			var hardshipId = $("#headshipIdHidden").val();
			$("#headshipId").combobox({
				url           : '/pc/employee/headships.htm?companyId=' + companyId,
				editable      : false,
				required      : true,
				panelHeight   : 200,
				valueField    : 'headshipId',
				textField     : 'headshipName',
				onLoadSuccess : function() {
					$("#headshipId").combobox('setValue', hardshipId);
				}
			});
		},
		
		initRole : function() {
			var roleId = $("#roleIdHidden").val();
			$("#roleId").combobox({
				url           : '/pc/employee/roles.htm',
				editable      : false,
				required      : true,
				panelHeight   : 200,
				valueField    : 'roleId',
				textField     : 'roleName',
				onLoadSuccess : function() {
					$("#roleId").combobox('setValue', roleId);
				}
			});
		},
		
		init : function() {
			EditEmployee.initRole();
			EditEmployee.getCompanyId();
		}
	};
}();

$(function(){
	EditEmployee.init();
});